package com.xy.p2p.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import com.xy.core.util.BeanUtil;
import com.xy.common.page.Pagination;
import com.xy.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xy.p2p.dao.TmemberbankcardDao;
import com.xy.p2p.model.Tmemberbankcard;
import com.xy.p2p.service.TmemberbankcardService;

@Service
@Transactional
public class TmemberbankcardServiceImpl extends BaseServiceImpl<Tmemberbankcard> implements
		TmemberbankcardService {
	private TmemberbankcardDao tmemberbankcardDao;

	public TmemberbankcardServiceImpl(TmemberbankcardDao paramAppRoleDao) {
		super(paramAppRoleDao);
		this.tmemberbankcardDao = paramAppRoleDao;
	}

	@Override
	public boolean checkExist(String paraName, String paraValue) {
		return tmemberbankcardDao.checkExist("Tmemberbankcard", paraName, paraValue);
	}

	@Override
	public List<Tmemberbankcard> getTmemberbankcard(Map<String, Object> map) {
		return tmemberbankcardDao.getTmemberbankcard(map);
	}
	@Override
	public Pagination getTmemberbankcardByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		// TODO Auto-generated method stub
		return tmemberbankcardDao.getTmemberbankcardByPage(map, pageNo, pageSize);
	}
	 
   @Override
	public Tmemberbankcard save(Tmemberbankcard tmemberbankcard) {
		// tmemberbankcard.setModtime(new Date());
		if (1 == tmemberbankcard.getIswithdraw()) {
			Map<String, Object> queryMap = new HashMap<String, Object>();
			queryMap.put("Tmember", tmemberbankcard.getTmember());
			List<Tmemberbankcard> list = tmemberbankcardDao.getTmemberbankcard(queryMap);
			for (Tmemberbankcard tempEntity : list) {
				tempEntity.setIswithdraw(0);
				tmemberbankcardDao.merge(tempEntity);
			}
		}
		if (tmemberbankcard.getMbcid() == null) {
			// 新增
			return super.save(tmemberbankcard);
		} else {
			// 更新
			Tmemberbankcard tmemberbankcard1 = tmemberbankcardDao.get(tmemberbankcard.getMbcid());
			try {
				BeanUtil.copyNotNullProperties(tmemberbankcard1, tmemberbankcard);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return super.save(tmemberbankcard1);
		}
	}
   
   @Override
	public void remove(Long paramPK) {
		// TODO Auto-generated method stub
		super.remove(paramPK);
   }
}